﻿@model IEnumerable<Shop.Models.DTO.OrderList>

@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutList.cshtml";
}

<form action="/admin/order/index" method="get">
    <span>订单状态</span>

    <select name="state" class="form-inline">
        <option value="-1" @(ViewBag.State==-1?"selected":"") >全部</option>
        <option value="0" @(ViewBag.State==0?"selected":"")>未付款</option>
        <option value="1" @(ViewBag.State==1?"selected":"")>已付款</option>
        <option value="2" @(ViewBag.State==2?"selected":"")>已发货</option>
        <option value="3" @(ViewBag.State==3?"selected":"")>已签收</option>
    </select>
    <button class="btn btn-primary">查询</button>
</form>
<table class="table">
    <tr>
        <th>
           客户
        </th>
        <th>
           状态
        </th>
        <th>
          下单时间
        </th>
        <th>
           总价
        </th>
        <th>
           收获地址
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            <td>
                @switch (item.State)
                {
                    case 0:
                        <span>未付款</span>
                        break;
                    case 1:
                        <span>已付款</span>
                        break;
                    case 2:
                        <span>已发货</span>
                        break;
                    case 3:
                        <span>已签收</span>
                        break;
                }

            </td>
        
                    <td>
                        @Html.DisplayFor(modelItem => item.CreateAt)
                    </td>
        
                    <td>
                        @Html.DisplayFor(modelItem => item.SumPrice)
                    </td>
        
                    <td>
                        @Html.DisplayFor(modelItem => item.Address)
                    </td>
        
                    <td>
                        @if (item.State == 1)
                        {
                            <a href="/admin/order/send/@item.Id">发货</a>
                        }
                        else if (item.State == 0)
                        {
                            <a href="/admin/order/delete/@item.Id">删除</a>
                        }
                    </td>
        
                </tr>
        
                <tr>
        
                    <td colspan="6">
        
                        <table class="table table-dark" style="background-color:#ccc">
                    <tr>
                        <td>商品</td>
                        <td>数量</td>
                        <td>规格</td>
                    </tr>
                    @foreach (var goods in item.Details)
                    {
                        <tr>
                            <td>
                                <img src="@goods.Pictrue" width="100" />
                                @goods.ProductInfoName
                            </td>
                            <td>@goods.Count</td>
                            <td>@goods.Specs</td>
                        </tr>
                    }
                </table>
            </td>
        </tr>
    }

</table>
<div>
    <span>共 @ViewBag.Total 条</span>
    @{ 
        var prevLink = "";
        if (ViewBag.Index == 1)
        {
            prevLink = "#";
        }
        else
        {
            int index = (int)ViewBag.Index--;
            prevLink = "/admin/order/index?state="+ViewBag.State+"&pageIndex=" + index;
        }

        var nextLink = "#";  // 下一页
        var pagecount = Math.Ceiling((int)ViewBag.Total / 5.0);

        if(ViewBag.Index!=pagecount)
        {
            int index = ++ViewBag.Index;
            nextLink = "/admin/order/index?state=" + ViewBag.State + "&pageIndex=" + index;
        }
    }
    <a href="@prevLink">上页</a>
    当前 @ViewBag.Index 页
    <a href="@nextLink">下页</a>
</div>
